//
//  NewLittleIdeaViewController.swift
//  elarc01
//
//  Created by elarc on 16/4/14.
//  Copyright © 2016年 elarc. All rights reserved.
//

import Foundation
class NewLittleIdeaViewController: BaseUIViewController,iCarouselDataSource,iCarouselDelegate {
    
    //icarousel
    var items:[Int] = []
    var carousel:iCarousel!
    
    
    var tempImage:UIImageView?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.whiteColor()
        tempImage = UIImageView()
        tempImage?.image = UIImage(named: "tabbar_home")
        tempImage!.frame = CGRectMake(100, 100, 100, 49)
        view.addSubview(tempImage!)
        tempImage!.boom()
        
        buildIcarousel()
    }
    
    func buildIcarousel() -> Void {
        for i in 0...99
        {
            items.append(i)
        }
        
        let image = UIImageView()
        image.image = UIImage(named: "rain")
        image.frame = CGRectMake(0, 0, ScreenWidth, ScreenWidth)
        self.view.addSubview(image)
//毛玻璃
        let blurEffect = UIBlurEffect(style: .Dark)
        let visualEffectView = UIVisualEffectView(effect: blurEffect)
        visualEffectView.frame = image.bounds
        image.addSubview(visualEffectView)
        
        carousel = iCarousel()
        carousel.delegate = self
        carousel.dataSource = self
        
        carousel.frame = CGRectMake(0, 0, ScreenWidth, ScreenWidth)
        self.view.addSubview(carousel)
        
        carousel.type = .Cylinder

    }
    
    func numberOfItemsInCarousel(carousel: iCarousel) -> Int
    {
        return items.count
    }
    
    func carousel(carousel: iCarousel, viewForItemAtIndex index: Int, reusingView view: UIView?) -> UIView
    {
        var label: UILabel
        var itemView: UIImageView
        
        //create new view if no view is available for recycling
        if (view == nil)
        {
            //don't do anything specific to the index within
            //this `if (view == nil) {...}` statement because the view will be
            //recycled and used with other index values later
            
            let image = UIImageView()
            image.image = UIImage(named: "panda04")
            image.frame = CGRectMake(0, 0, 200, 200)
            
            
            
            itemView = UIImageView(frame:CGRect(x:0, y:0, width:200, height:200))
            itemView.image = UIImage(named: "shadowbg")
            itemView.contentMode = .Center
            
            itemView.addSubview(image)
            
            label = UILabel(frame:itemView.bounds)
            label.backgroundColor = UIColor.clearColor()
            label.textAlignment = .Center
            label.font = label.font.fontWithSize(50)
            label.tag = 1
            itemView.addSubview(label)
        }
        else
        {
            //get a reference to the label in the recycled view
            itemView = view as! UIImageView;
            label = itemView.viewWithTag(1) as! UILabel!
        }
        
        //set item label
        //remember to always set any properties of your carousel item
        //views outside of the `if (view == nil) {...}` check otherwise
        //you'll get weird issues with carousel item content appearing
        //in the wrong place in the carousel
        label.text = "\(items[index])"
        
        return itemView
    }
    
    func carousel(carousel: iCarousel, valueForOption option: iCarouselOption, withDefault value: CGFloat) -> CGFloat
    {
        if (option == .Spacing)
        {
            return value * 1.1
        }
        return value
    }
    
    func carousel(carousel: iCarousel, didSelectItemAtIndex index: Int) {
        print(index)
    }
    
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        tempImage?.boom()
   }
}